<template>
	<wsPage title="推送">
		<div slot="page_operate">
			<Button  @click="queryBase"><Icon type="refresh"></Icon><span>刷新</span></Button>
		</div>
		<Row class="tab-demo">
			<Col span="24">
				<Button :type="activeIndex == 0 ? 'primary' : ''" @click="queryBase()">基地</Button>
				<Button :type="activeIndex == 1 ? 'primary' : ''" @click="queryProduct()">商品</Button>
				<Button :type="activeIndex == 2 ? 'primary' : ''" @click="queryContent()">资讯</Button>
				<Button :type="activeIndex == 3 ? 'primary' : ''" @click="queryMedical()">健康项目</Button>
			</Col>
		</Row>
		<!-- 基地列表 -->
		<wsSmPanel :page="baseTable.basePage" @simple-query="queryBase" @page-change="queryBase" v-show="this.activeIndex == 0">
			<div slot="list_data">
				<Table border :columns="baseTable.columns" :data="baseTable.data"></Table>
			</div>
		</wsSmPanel>
		<!-- 商品列表 -->
		<wsSmPanel :page="productTable.productPage" @simple-query="queryProduct" @page-change="queryProduct" v-show="this.activeIndex == 1">
			<div slot="list_data">
				<Table border :columns="productTable.columns" :data="productTable.data"></Table>
			</div>
		</wsSmPanel>
		<!-- 资讯列表 -->
		<wsSmPanel :page="contentTable.contentPage" @simple-query="queryContent" @page-change="queryContent" v-show="this.activeIndex == 2">
			<div slot="list_data">
				<Table border :columns="contentTable.columns" :data="contentTable.data"></Table>
			</div>
		</wsSmPanel>
		<!-- 健康项目列表 -->
		<wsSmPanel :page="medicalTable.medicalPage" @simple-query="queryMedical" @page-change="queryMedical" v-show="this.activeIndex == 3">
			<div slot="list_data">
				<Table border :columns="medicalTable.columns" :data="medicalTable.data"></Table>
			</div>
		</wsSmPanel>

	</wsPage>
</template>

<script>
import Common from '../../../common/common.js';
	export default {
		data() {
			return {
				paramsBase: {
                	name: '',
                	operationStatus: ''
                },
                paramsContent: {
                	name: '',
                	publicationType: ''
                },
                paramsProduct: {
                	name: '',
                	status: null
                },
                paramsMedical: {
                	name: '',
                	publicationType: ''
                },
                pushMessage: {
                	id: '',
                	name: '',
                	type: ''
                },
				baseTable: {
					columns: [{
						title: '名称',
                        key: 'name',
                        align: 'center'
					},
					{
						title: '地址',
                        key: 'address',
                        align: 'center'
					},
					{
						title: '操作',
						width: 200,
						fixed: 'right',
						align: 'center',
						render: (h, params) => {
							return h('div', [h('Button', {
								props: {
                                    type: 'text',
                                    size: 'small'
                                },
								on: {
									click: () => {
										this.pushMessage.id = params.row.id;
										this.pushMessage.name = params.row.name;
										this.pushMessage.type = 6;
										this.push();
									}
								}
							}, "推送")])
						}
					}],
					data: [],
					basePage: {
						total: 0, //总条数
						pageNum: 1, //当前页
						pageSize: 10 //每页显示条数
					},
					currentRow: [], //选中
				},
				contentTable: {
					columns: [{
						title: '名称',
                        key: 'name',
                        align: 'center'
					},
					{
						title: '栏目',
                        key: 'columnName',
                        align: 'center'
					},
					{
						title: '操作',
						width: 200,
						fixed: 'right',
						align: 'center',
						render: (h, params) => {
							return h('div', [h('Button', {
								props: {
                                    type: 'text',
                                    size: 'small'
                                },
								on: {
									click: () => {
										this.pushMessage.id = params.row.id;
										this.pushMessage.name = params.row.name;
										this.pushMessage.type = 5;
										this.push();
									}
								}
							}, "推送")])
						}
					}],
					data: [],
					contentPage: {
						total: 0, //总条数
						pageNum: 1, //当前页
						pageSize: 10 //每页显示条数
					},
					currentRow: [], //选中
				},
				productTable: {
					columns: [{
						title: '名称',
                        key: 'name',
                        align: 'center'
					},
					{
						title: '所属分类',
                        key: 'catagoryName',
                        align: 'center'
					},
					{
						title: '操作',
						width: 200,
						fixed: 'right',
						align: 'center',
						render: (h, params) => {
							return h('div', [h('Button', {
								props: {
                                    type: 'text',
                                    size: 'small'
                                },
								on: {
									click: () => {
										this.pushMessage.id = params.row.id;
										this.pushMessage.name = params.row.name;
										this.pushMessage.type = 7;
										this.push();
									}
								}
							}, "推送")])
						}
					}],
					data: [],
					productPage: {
						total: 0, 		//总条数
						pageNum: 1, 	//当前页
						pageSize: 10 	//每页显示条数
					},
					currentRow: [], 	//选中
				},
				medicalTable: {
					columns: [{
						title: '名称',
                        key: 'name',
                        align: 'center'
					},
					{
						title: '项目分类',
                        key: 'servicesCategoryName',
                        align: 'center'
					},
					{
						title: '操作',
						width: 200,
						fixed: 'right',
						align: 'center',
						render: (h, params) => {
							return h('div', [h('Button', {
								props: {
                                    type: 'text',
                                    size: 'small'
                                },
								on: {
									click: () => {
										this.pushMessage.id = params.row.id;
										this.pushMessage.name = params.row.name;
										this.pushMessage.type = 8;
										this.push();
									}
								}
							}, "推送")])
						}
					}],
					data: [],
					medicalPage: {
						total: 0, 		//总条数
						pageNum: 1, 	//当前页
						pageSize: 10 	//每页显示条数
					},
					currentRow: [], 	//选中
				},
				activeIndex: 0
			}
		},
		computed: {

		},
		mounted() {
			this.init();
		},
		methods: {

			init() {
				this.queryBase();
			},
			/**
			 * 查询本地基地信息
			 */
			queryBase(){
				this.productTable.productPage.pageNum = 1;
				this.contentTable.contentPage.pageNum = 1;
				this.medicalTable.medicalPage.pageNum = 1;
				this.activeIndex = 0;
				this.paramsBase.operationStatus = 1;
				//发送查询请求
				let pageSize = this.baseTable.basePage.pageSize;
				let pageNum = this.baseTable.basePage.pageNum;
				const _this = this;
		        this.axios.post('/ws/ops/bases?pageNum='+pageNum+'&pageSize='+pageSize, _this.paramsBase).then(function (response) {
					var res = response.data;
			        var resMeta = res.meta;
			        if(0 == resMeta.code) {
			          	_this.buildPageBaseData(res.data);
			        } else {
			        	_this.$Message.warning(resMeta.message);
			        }
		        });
			},
			/**
			 * 构建表格数据
			 */
			buildPageBaseData(data_) {
				this.baseTable.data = data_.list;
				this.baseTable.basePage.total = data_.total;
			},
			/**
			 * 查询本地新闻信息
			 */
			queryContent(){
				this.baseTable.basePage.pageNum = 1;
				this.productTable.productPage.pageNum = 1;
				this.medicalTable.medicalPage.pageNum = 1;
				this.activeIndex = 2;
				this.paramsContent.publicationType = 1;
				let pageSize = this.contentTable.contentPage.pageSize;
				let pageNum = this.contentTable.contentPage.pageNum;
				const _this = this;
				//发送查询请求
		        this.axios.post('/ws/ops/contents?pageNum=' + pageNum + '&pageSize=' + pageSize, _this.paramsContent).then(function (response) {
					var res = response.data;
			        var resMeta = res.meta;
			        if(0 == resMeta.code) {
			          	_this.buildPageContentData(res.data);
			        } else {
			          	_this.$Message.warning(resMeta.message);
			        }
		        });
			},
			/**
			 * 构建表格数据
			 */
			buildPageContentData(data_) {
				this.contentTable.data = data_.list;
				this.contentTable.contentPage.total = data_.total;
			},
			/**
			 * 查询本地产品信息
			 */
			queryProduct(){
				this.baseTable.basePage.pageNum = 1;
				this.contentTable.contentPage.pageNum = 1;
				this.medicalTable.medicalPage.pageNum = 1;
				this.activeIndex = 1;
				//发送查询请求
				this.paramsProduct.status=4;
				let pageSize = this.productTable.productPage.pageSize;
				let pageNum = this.productTable.productPage.pageNum;
				const _this = this;
		        this.axios.post('/ws/ms/products?pageNum=' + pageNum + '&pageSize=' + pageSize, this.paramsProduct).then(function (response) {
					var res = response.data;
			        var resMeta = res.meta;
			        if(0 == resMeta.code) {
			          	_this.buildPageProductData(res.data);
			        } else {
			          	_this.$Message.warning(resMeta.message);
			        }
		        });
			},
			/**
			 * 构建表格数据
			 */
			buildPageProductData(data_) {
				this.productTable.data = data_.list;
				this.productTable.productPage.total = data_.total;
			},

			/**
			 * 查询健康项目信息
			 */
			queryMedical(){
				this.baseTable.basePage.pageNum = 1;
				this.productTable.productPage.pageNum = 1;
				this.contentTable.contentPage.pageNum = 1;
				this.activeIndex = 3;
				this.paramsMedical.publicationType = 1;
				//发送查询请求
				let pageSize = this.medicalTable.medicalPage.pageSize;
				let pageNum = this.medicalTable.medicalPage.pageNum;
				const _this = this;
		        this.axios.post('/ws/ops/medicalServicess?pageNum=' + pageNum + '&pageSize=' + pageSize, this.paramsMedical).then(function (response) {
					var res = response.data;
			        var resMeta = res.meta;
			        if(0 == resMeta.code) {
			          	_this.buildPageMedicalData(res.data);
			        } else {
			          	_this.$Message.warning(resMeta.message);
			        }
		        });
			},
			/**
			 * 构建表格数据
			 */
			buildPageMedicalData(data_) {
				this.medicalTable.data = data_.list;
				this.medicalTable.medicalPage.total = data_.total;
			},
			//作废会员卡
			push(){
				const _this = this;
				this.$confirm({
        			title: '操作提示',
        			width: 300,
        			content: '你确认推送吗?',
        			onOk: function() {
        				_this.pushMessageOK();
        			}
        		});	
			},
			//推送
			pushMessageOK(){
				const _this = this;
				this.axios.post('/ws/ops/push', _this.pushMessage).then(response => {
					let res = response.data;
					if(0 === res.meta.code) {
						_this.$Message.success('推送成功');
					} else {
						let message_ = res.meta.message;
						_this.$Message.warning('推送失败:' + message_);
					}
					if(_this.pushMessage.type == 6){//推送基地
						_this.queryBase();
					}
					if(_this.pushMessage.type == 7){//推送商品
						_this.queryProduct();
					}
					if(_this.pushMessage.type == 5){//推送资讯
						_this.queryContent();
					}
					if(_this.pushMessage.type == 8){//推送健康项目
						_this.queryMedical();
					}
					
				});
			}


		}
	}
</script>

<style scoped>
	.ws-form-select {
		width: 162px;
	}
</style>
